package fr.emn.fil.soc.gr3.restws.impl;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import fr.emn.fil.soc.gr3.entites.Sujet;
import fr.emn.fil.soc.gr3.restws.DBConnection;
import fr.emn.fil.soc.gr3.restws.ProtocoleEtudiant;
import fr.emn.fil.soc.gr3.restws.TokenUtil;

public class ProtocoleEtudiantImpl implements ProtocoleEtudiant {

	@Override
	public Sujet recupererSujet(String token, int idSujet) {
		Sujet sujet = null;
		boolean tokenValide = TokenUtil.tokenExists(token);

		if (tokenValide) {
			DBConnection dbConnection = new DBConnection();
			EntityManager em = dbConnection.createConnection();

			Query query = em.createQuery("SELECT s FROM "
					+ Sujet.class.getName() + " s WHERE s.id=:id");
			query.setParameter("id", idSujet);

			try {
				sujet = (Sujet) query.getSingleResult();
			} catch (Exception e) {

			}

			dbConnection.closeConnection();
		}

		return sujet;
	}

	@Override
	public void evaluerReponse(String token) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean validerEvaluation(String token) {
		// TODO Auto-generated method stub
		return false;
	}

}
